{
  "name": "Case 85 - Social Media Manager - Health & Fitness News Tracker",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -1104,
        -176
      ],
      "id": "87cca9f2-2691-4f2c-be3e-d54b8f588a21",
      "name": "Weekly Schedule - Monday 9 AM"
    },
    {
      "parameters": {
        "actorId": {
          "__rl": true,
          "value": "buIWk2uOUzTmcLsuB",
          "mode": "list",
          "cachedResultName": "Linkedin Post Search Scraper (No Cookies) (harvestapi/linkedin-post-search)",
          "cachedResultUrl": "https://console.apify.com/actors/buIWk2uOUzTmcLsuB/input"
        },
        "customBody": "{\n  \"authorUrls\": [\n    \"https://www.linkedin.com/company/mens-health-magazine\",\n    \"https://www.linkedin.com/company/womens-health-magazine\",\n    \"https://www.linkedin.com/company/healthline\",\n    \"https://www.linkedin.com/company/webmd\",\n    \"https://www.linkedin.com/company/myfitnesspal\",\n    \"https://www.linkedin.com/company/peloton-interactive\",\n    \"https://www.linkedin.com/company/nike\",\n    \"https://www.linkedin.com/company/lululemon\"\n  ],\n  \"searchQueries\": [\n    \"new study\",\n    \"research shows\",\n    \"trending\",\n    \"health news\",\n    \"fitness trend\",\n    \"study finds\"\n  ],\n  \"maxPosts\": 50,\n  \"scrapeComments\": false,\n  \"scrapeReactions\": false\n}"
      },
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        -912,
        -176
      ],
      "id": "984dce9f-2f4a-4377-908b-9d6220f34cc7",
      "name": "Scrape LinkedIn Health & Fitness News",
      "credentials": {
        "apifyApi": {
          "id": "w5S6YBbbyUddEfQA",
          "name": "Apify account"
        }
      }
    },
    {
      "parameters": {
        "resource": "Datasets",
        "datasetId": "={{ $json.defaultDatasetId }}"
      },
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        -720,
        -176
      ],
      "id": "d1ae9929-0149-4fcb-b0c1-37a4f4ae807d",
      "name": "Get Dataset Items",
      "credentials": {
        "apifyApi": {
          "id": "w5S6YBbbyUddEfQA",
          "name": "Apify account"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4o-mini"
        },
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You are a Health & Fitness News Validation Expert.\n\nAnalyze LinkedIn posts to determine if they are genuine health/fitness news or trends.\n\nReturn ONLY valid JSON in this exact format:\n{\n  \"is_health_news\": \"yes|no\",\n  \"confidence\": 0.95,\n  \"reason\": \"brief explanation\"\n}\n\nCriteria for \"yes\" (genuine health/fitness news):\n✅ Reports new research findings or studies\n✅ Announces emerging health/fitness trends\n✅ Shares expert health advice or recommendations\n✅ Discusses breakthrough treatments or approaches\n✅ Reports on health data, statistics, or surveys\n✅ Covers nutrition science updates\n✅ Discusses fitness methodology innovations\n✅ Mental health research or insights\n✅ Sleep science findings\n✅ Wellness trend analysis\n\nCriteria for \"no\" (NOT genuine news):\n❌ Product promotions or advertisements\n❌ Personal workout achievements (\"I ran 5K today\")\n❌ Gym selfies or transformation photos without insight\n❌ Motivational quotes without news value\n❌ Sales pitches for supplements/equipment\n❌ Class schedules or event announcements\n❌ Generic fitness tips without research backing\n❌ Influencer personal routines without educational value\n\nRules:\n1. confidence: 0-1 scale (0.9+ for very clear news/trends)\n2. reason: 1 sentence explaining the decision\n3. Be strict - require actual news value or trend insight\n4. Return ONLY the JSON object, no explanations"
            },
            {
              "content": "=Analyze this LinkedIn post to determine if it's genuine health/fitness news:\n\nAuthor: {{ $json.author.name }}\nPost Date: {{ $json.postedAt.date }}\nPost Content: {{ $json.content }}\n\nReturn only JSON."
            }
          ]
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        -576,
        -176
      ],
      "id": "47e65841-473b-4dc1-8952-2553f80cd4be",
      "name": "AI Validation Filter",
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// UNIVERSAL AI RESPONSE PARSER - Same code for ALL cases\nconst items = [];\nconst input = $input.all();\n\nfunction extractJSON(text) {\n  const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n  if (!jsonMatch) return null;\n  return jsonMatch[0];\n}\n\ninput.forEach((item, index) => {\n  try {\n    let aiText = item.json.output[0].content[0].text || '';\n    \n    // Clean markdown code blocks\n    aiText = aiText\n      .replace(/```json/gi, '')\n      .replace(/```/g, '')\n      .trim();\n    \n    // Extract JSON object\n    const jsonStr = extractJSON(aiText);\n    \n    if (!jsonStr) {\n      throw new Error('No JSON found in AI response');\n    }\n    \n    // Parse and return clean JSON\n    const parsed = JSON.parse(jsonStr);\n    items.push({ json: parsed });\n    \n  } catch (error) {\n    console.error(`Parse error for item ${index}:`, error.message);\n    // Return empty object on error - no case-specific fields\n    items.push({ json: {} });\n  }\n});\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -304,
        -176
      ],
      "id": "6e636067-8c99-43d1-9b50-c33efaeb8b1f",
      "name": "Parse AI Validation"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "is_health_news",
              "name": "is_health_news",
              "value": "={{ $json.is_health_news }}",
              "type": "string"
            },
            {
              "id": "confidence",
              "name": "confidence",
              "value": "={{ $json.confidence }}",
              "type": "number"
            },
            {
              "id": "reason",
              "name": "reason",
              "value": "={{ $json.reason }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -128,
        -176
      ],
      "id": "71be1443-29bd-433d-a9c2-377e6fa3def3",
      "name": "Edit Fields - Validation"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "condition-001",
              "leftValue": "={{ $json.is_health_news }}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        64,
        -176
      ],
      "id": "5b027759-1774-4107-9722-ef1449bfa1b1",
      "name": "Filter Only Health News"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4o-mini"
        },
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You are a Social Media Content Strategy Analyst.\n\nExtract structured health/fitness news information from LinkedIn posts to inform content strategy.\n\nReturn ONLY valid JSON in this exact format:\n{\n  \"news_topic\": \"Brief headline/topic (max 100 chars)\",\n  \"topic_category\": \"Nutrition|Fitness|Mental Health|Sleep|Recovery|Supplements|Weight Loss|Strength Training|Cardio|Yoga|Wellness|Other\",\n  \"trend_virality\": \"High|Medium|Low\",\n  \"content_angle\": \"Educational|Inspirational|Controversial|How-to|News Report|Expert Opinion\",\n  \"source_credibility\": \"Peer-reviewed Study|Medical Expert|Fitness Influencer|Brand|News Outlet|Other\",\n  \"shareability_score\": \"High|Medium|Low - how likely to go viral?\",\n  \"optimal_platform\": \"Instagram|LinkedIn|TikTok|Facebook|Twitter|Multiple\",\n  \"hashtags_mentioned\": [\"#hashtag1\", \"#hashtag2\", \"#hashtag3\"],\n  \"content_idea\": \"Suggested post angle for our brand (max 150 chars)\",\n  \"urgency\": \"Post Today|Post This Week|Evergreen Content\"\n}\n\nExtraction Rules:\n1. news_topic: Create concise headline\n2. topic_category: Categorize into fitness/health domain\n3. trend_virality (based on engagement + topic novelty):\n   - High = 500+ engagement, controversial/new topic\n   - Medium = 100-499 engagement, interesting topic\n   - Low = <100 engagement, niche topic\n4. content_angle: How is this being presented?\n5. source_credibility: Evaluate source authority\n6. shareability_score:\n   - High = Surprising, actionable, or controversial\n   - Medium = Interesting but not groundbreaking\n   - Low = Niche or technical\n7. optimal_platform: Best social media platform for this content type\n8. hashtags_mentioned: Extract all hashtags (up to 5)\n9. content_idea: How can our brand repurpose this?\n10. urgency: Time-sensitivity for posting\n\nReturn ONLY the JSON object, no explanations."
            },
            {
              "content": "=Extract health/fitness news intelligence from this LinkedIn post:\n\nAuthor: {{ $('Get Dataset Items').item.json.author.name }}\nPost Date: {{ $('Get Dataset Items').item.json.postedAt.date }}\nPost Content: {{ $('Get Dataset Items').item.json.content }}\nEngagement: {{ $('Get Dataset Items').item.json.engagement.likes }} likes, {{ $('Get Dataset Items').item.json.engagement.comments }} comments, {{ $('Get Dataset Items').item.json.engagement.shares }} shares\n\nReturn only JSON."
            }
          ]
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        208,
        -176
      ],
      "id": "057444a9-331b-44df-876a-087a2db0142c",
      "name": "AI Extract News Intelligence",
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// UNIVERSAL AI RESPONSE PARSER - Same code for ALL cases\nconst items = [];\nconst input = $input.all();\n\nfunction extractJSON(text) {\n  const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n  if (!jsonMatch) return null;\n  return jsonMatch[0];\n}\n\ninput.forEach((item, index) => {\n  try {\n    let aiText = item.json.output[0].content[0].text || '';\n    \n    // Clean markdown code blocks\n    aiText = aiText\n      .replace(/```json/gi, '')\n      .replace(/```/g, '')\n      .trim();\n    \n    // Extract JSON object\n    const jsonStr = extractJSON(aiText);\n    \n    if (!jsonStr) {\n      throw new Error('No JSON found in AI response');\n    }\n    \n    // Parse and return clean JSON\n    const parsed = JSON.parse(jsonStr);\n    items.push({ json: parsed });\n    \n  } catch (error) {\n    console.error(`Parse error for item ${index}:`, error.message);\n    // Return empty object on error - no case-specific fields\n    items.push({ json: {} });\n  }\n});\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        -176
      ],
      "id": "f2307bd3-41c8-46ea-8ba9-a560e9cc6d76",
      "name": "Parse AI Response"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "timestamp",
              "name": "found_date",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            },
            {
              "id": "source_name",
              "name": "source_name",
              "value": "={{ $('Get Dataset Items').item.json.author?.name || 'unknown' }}",
              "type": "string"
            },
            {
              "id": "news_topic",
              "name": "news_topic",
              "value": "={{ $json.news_topic }}",
              "type": "string"
            },
            {
              "id": "topic_category",
              "name": "topic_category",
              "value": "={{ $json.topic_category }}",
              "type": "string"
            },
            {
              "id": "trend_virality",
              "name": "trend_virality",
              "value": "={{ $json.trend_virality }}",
              "type": "string"
            },
            {
              "id": "content_angle",
              "name": "content_angle",
              "value": "={{ $json.content_angle }}",
              "type": "string"
            },
            {
              "id": "source_credibility",
              "name": "source_credibility",
              "value": "={{ $json.source_credibility }}",
              "type": "string"
            },
            {
              "id": "shareability",
              "name": "shareability_score",
              "value": "={{ $json.shareability_score }}",
              "type": "string"
            },
            {
              "id": "platform",
              "name": "optimal_platform",
              "value": "={{ $json.optimal_platform }}",
              "type": "string"
            },
            {
              "id": "hashtags",
              "name": "hashtags_mentioned",
              "value": "={{ $json.hashtags_mentioned }}",
              "type": "array"
            },
            {
              "id": "content_idea",
              "name": "content_idea",
              "value": "={{ $json.content_idea }}",
              "type": "string"
            },
            {
              "id": "urgency",
              "name": "urgency",
              "value": "={{ $json.urgency }}",
              "type": "string"
            },
            {
              "id": "post_content",
              "name": "post_content",
              "value": "={{ $('Get Dataset Items').item.json.content || '' }}",
              "type": "string"
            },
            {
              "id": "post_date",
              "name": "post_date",
              "value": "={{ $('Get Dataset Items').item.json.postedAt?.date || '' }}",
              "type": "string"
            },
            {
              "id": "post_url",
              "name": "post_url",
              "value": "={{ $('Get Dataset Items').item.json.linkedinUrl || '' }}",
              "type": "string"
            },
            {
              "id": "likes",
              "name": "likes_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.likes || 0 }}",
              "type": "number"
            },
            {
              "id": "comments",
              "name": "comments_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.comments || 0 }}",
              "type": "number"
            },
            {
              "id": "shares",
              "name": "shares_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.shares || 0 }}",
              "type": "number"
            },
            {
              "id": "total_engagement",
              "name": "engagement_total",
              "value": "={{ ($('Get Dataset Items').item.json.engagement?.likes || 0) + ($('Get Dataset Items').item.json.engagement?.comments || 0) + ($('Get Dataset Items').item.json.engagement?.shares || 0) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        640,
        -176
      ],
      "id": "dcb06b42-25f2-455c-bcf8-4642272bfb61",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "12SU47GhYoKDq6C-w7Soswb14vRx9Ta5ORSdpqPNwztY",
          "mode": "list",
          "cachedResultName": "Case 85 - Health & Fitness News Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/12SU47GhYoKDq6C-w7Soswb14vRx9Ta5ORSdpqPNwztY/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/12SU47GhYoKDq6C-w7Soswb14vRx9Ta5ORSdpqPNwztY/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Found_Date": "={{ $json.found_date }}",
            "Source_Name": "={{ $json.source_name }}",
            "News_Topic": "={{ $json.news_topic }}",
            "Topic_Category": "={{ $json.topic_category }}",
            "Trend_Virality": "={{ $json.trend_virality }}",
            "Content_Angle": "={{ $json.content_angle }}",
            "Source_Credibility": "={{ $json.source_credibility }}",
            "Shareability_Score": "={{ $json.shareability_score }}",
            "Optimal_Platform": "={{ $json.optimal_platform }}",
            "Hashtags_Mentioned": "={{ $json.hashtags_mentioned.join(' ') }}",
            "Content_Idea": "={{ $json.content_idea }}",
            "Urgency": "={{ $json.urgency }}",
            "Post_Date": "={{ $json.post_date }}",
            "Likes": "={{ $json.likes_count }}",
            "Comments": "={{ $json.comments_count }}",
            "Shares": "={{ $json.shares_count }}",
            "Total_Engagement": "={{ $json.engagement_total }}",
            "Post_URL": "={{ $json.post_url }}",
            "Post_Content": "={{ $json.post_content }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Found_Date",
              "displayName": "Found_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Source_Name",
              "displayName": "Source_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "News_Topic",
              "displayName": "News_Topic",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Topic_Category",
              "displayName": "Topic_Category",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Trend_Virality",
              "displayName": "Trend_Virality",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Content_Angle",
              "displayName": "Content_Angle",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Source_Credibility",
              "displayName": "Source_Credibility",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Shareability_Score",
              "displayName": "Shareability_Score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Optimal_Platform",
              "displayName": "Optimal_Platform",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Hashtags_Mentioned",
              "displayName": "Hashtags_Mentioned",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Content_Idea",
              "displayName": "Content_Idea",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Urgency",
              "displayName": "Urgency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_Date",
              "displayName": "Post_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Likes",
              "displayName": "Likes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Comments",
              "displayName": "Comments",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Shares",
              "displayName": "Shares",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Total_Engagement",
              "displayName": "Total_Engagement",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_URL",
              "displayName": "Post_URL",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_Content",
              "displayName": "Post_Content",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        816,
        -176
      ],
      "id": "f42dbd68-d990-4c16-8aaa-5995b3b567b4",
      "name": "Log to Content Calendar",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Aggregate all items from Google Sheets into email-ready summary\nconst allItems = $input.all();\n\n// Count by topic category\nconst categoryCounts = {};\nallItems.forEach(item => {\n  const category = item.json.Topic_Category || 'Other';\n  categoryCounts[category] = (categoryCounts[category] || 0) + 1;\n});\n\nconst topCategories = Object.entries(categoryCounts)\n  .sort((a, b) => b[1] - a[1]);\n\n// Count by virality\nconst viralityCounts = {};\nallItems.forEach(item => {\n  const virality = item.json.Trend_Virality || 'Unknown';\n  viralityCounts[virality] = (viralityCounts[virality] || 0) + 1;\n});\n\n// Count by urgency\nconst urgencyCounts = {};\nallItems.forEach(item => {\n  const urgency = item.json.Urgency || 'Evergreen';\n  urgencyCounts[urgency] = (urgencyCounts[urgency] || 0) + 1;\n});\n\n// High virality + high shareability content\nconst viralContent = allItems.filter(item => \n  item.json.Trend_Virality === 'High' && item.json.Shareability_Score === 'High'\n);\n\n// Urgent content (post today)\nconst urgentContent = allItems.filter(item => \n  item.json.Urgency === 'Post Today'\n);\n\n// Count by platform\nconst platformCounts = {};\nallItems.forEach(item => {\n  const platform = item.json.Optimal_Platform || 'Multiple';\n  platformCounts[platform] = (platformCounts[platform] || 0) + 1;\n});\n\n// All hashtags mentioned (frequency)\nconst hashtagCounts = {};\nallItems.forEach(item => {\n  const hashtagsString = item.json.Hashtags_Mentioned || '';\n  if (hashtagsString) {\n    const hashtags = hashtagsString.split(' ').filter(h => h.startsWith('#'));\n    hashtags.forEach(tag => {\n      hashtagCounts[tag] = (hashtagCounts[tag] || 0) + 1;\n    });\n  }\n});\n\nconst trendingHashtags = Object.entries(hashtagCounts)\n  .sort((a, b) => b[1] - a[1])\n  .slice(0, 10);\n\n// Build HTML table rows\nconst tableRows = allItems.map(item => {\n  const data = item.json;\n  const viralityColor = data.Trend_Virality === 'High' ? '#dc3545' : \n                        data.Trend_Virality === 'Medium' ? '#ffc107' : '#28a745';\n  const urgencyColor = data.Urgency === 'Post Today' ? '#dc3545' : \n                       data.Urgency === 'Post This Week' ? '#ffc107' : '#6c757d';\n  \n  return `\n    <tr>\n      <td>${data.News_Topic || 'N/A'}</td>\n      <td>${data.Topic_Category || 'N/A'}</td>\n      <td><span style=\"color: ${viralityColor}; font-weight: bold;\">${data.Trend_Virality || 'N/A'}</span></td>\n      <td>${data.Shareability_Score || 'N/A'}</td>\n      <td><span style=\"color: ${urgencyColor}; font-weight: bold;\">${data.Urgency || 'N/A'}</span></td>\n      <td>${data.Optimal_Platform || 'N/A'}</td>\n      <td><a href=\"${data.Post_URL || '#'}\">View</a></td>\n    </tr>\n  `;\n}).join('');\n\n// Return single aggregated item\nreturn {\n  json: {\n    week_start: new Date(Date.now() - 7*24*60*60*1000).toISOString().split('T')[0],\n    week_end: new Date().toISOString().split('T')[0],\n    total_news_items: allItems.length,\n    category_breakdown: topCategories,\n    virality_breakdown: Object.entries(viralityCounts),\n    urgency_breakdown: Object.entries(urgencyCounts),\n    viral_content_count: viralContent.length,\n    urgent_content_count: urgentContent.length,\n    platform_breakdown: Object.entries(platformCounts),\n    trending_hashtags: trendingHashtags,\n    table_rows: tableRows,\n    all_news: allItems.map(item => item.json)\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        992,
        -176
      ],
      "id": "fcdf8ba2-eb1d-4938-b8b1-8c694f16115a",
      "name": "Aggregate Weekly Summary"
    },
    {
      "parameters": {
        "sendTo": "social-media-team@company.com",
        "subject": "=📊 Weekly Health & Fitness Content Ideas: {{ $json.week_start }} to {{ $json.week_end }}",
        "message": "=WEEKLY HEALTH & FITNESS CONTENT INTELLIGENCE\n================================================\nReport Period: {{ $json.week_start }} to {{ $json.week_end }}\n\nOVERVIEW:\nTotal Trending Topics Found: {{ $json.total_news_items }}\nHigh Viral Potential: {{ $json.viral_content_count }}\nPost Today (Urgent): {{ $json.urgent_content_count }}\n\nTOP TRENDING CATEGORIES:\n{{ $json.category_breakdown.map(([category, count]) => category + ': ' + count + ' topics').join('\\n') }}\n\nVIRALITY BREAKDOWN:\n{{ $json.virality_breakdown.map(([virality, count]) => virality + ': ' + count).join('\\n') }}\n\nCONTENT URGENCY:\n{{ $json.urgency_breakdown.map(([urgency, count]) => urgency + ': ' + count).join('\\n') }}\n\nOPTIMAL PLATFORM DISTRIBUTION:\n{{ $json.platform_breakdown.map(([platform, count]) => platform + ': ' + count).join('\\n') }}\n\nTRENDING HASHTAGS:\n{{ $json.trending_hashtags.map(([tag, count], i) => (i+1) + '. ' + tag + ' (' + count + ' mentions)').join('\\n') }}\n\n🔥 ACTION REQUIRED:\n⚡ {{ $json.urgent_content_count }} topics need immediate posts today!\n🚀 {{ $json.viral_content_count }} high-viral-potential content ideas ready!\n\nFull content calendar with post ideas in Google Sheets.\n\nGenerated: {{ new Date().toLocaleDateString() }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1168,
        -176
      ],
      "id": "3fce74de-927f-4c41-91a2-39a04adeb1ee",
      "name": "Send Weekly Content Digest",
      "webhookId": "4bd3ad8a-5a85-41ed-8803-6538318a5837",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Weekly Schedule - Monday 9 AM": {
      "main": [
        [
          {
            "node": "Scrape LinkedIn Health & Fitness News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape LinkedIn Health & Fitness News": {
      "main": [
        [
          {
            "node": "Get Dataset Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Dataset Items": {
      "main": [
        [
          {
            "node": "AI Validation Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Validation Filter": {
      "main": [
        [
          {
            "node": "Parse AI Validation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Validation": {
      "main": [
        [
          {
            "node": "Edit Fields - Validation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields - Validation": {
      "main": [
        [
          {
            "node": "Filter Only Health News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Only Health News": {
      "main": [
        [
          {
            "node": "AI Extract News Intelligence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Extract News Intelligence": {
      "main": [
        [
          {
            "node": "Parse AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Response": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Log to Content Calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Content Calendar": {
      "main": [
        [
          {
            "node": "Aggregate Weekly Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Weekly Summary": {
      "main": [
        [
          {
            "node": "Send Weekly Content Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "95c41719-7f81-4fc0-8487-297fc3311f2f",
  "meta": {
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "f9FRSL7eLskE2fe3",
  "tags": []
}